﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Player : MonoBehaviour {



    public Text healthTxt;
    public float speed;
    private Rigidbody2D rb;
    private Vector2 moveVelovity;
    public int health = 10;
	// Use this for initialization
	void Start () {

        rb = GetComponent<Rigidbody2D>();

	}
	
	// Update is called once per frame
	void Update () {

        if(health<=0){

            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            return;
        }



        Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        moveVelovity = moveInput.normalized*speed;
        healthTxt.text = "" + health;

	}

	public void FixedUpdate()
	{

        rb.MovePosition(rb.position + moveVelovity * Time.fixedDeltaTime);
	}

	
}
